package com.youan.serve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youan.serve.dao.domain.Syscode;
import com.youan.serve.dao.domain.SyscodeDetail;
import com.youan.serve.dao.idao.SyscodeDetailMapper;
import com.youan.serve.dao.idao.SyscodeMapper;
import com.youan.serve.service.ISystemService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: 辛晟昊
 * @time: 2020/3/13 11:31
 */
@Service
public class SystemServiceImpl implements ISystemService {
    @Autowired
    private SyscodeMapper syscodeMapper;
    @Autowired
    private SyscodeDetailMapper syscodeDetailMapper;

    @Override
    public List<SyscodeDetail> getCodes(String codeName) {
        List<Syscode> syscodes = syscodeMapper.selectList(new LambdaQueryWrapper<Syscode>().eq(Syscode::getCodeName, codeName));
        int size = CollectionUtils.size(syscodes);
        if( size > 1){
            return new ArrayList<SyscodeDetail>();
        }else if(size == 0){
            return new ArrayList<SyscodeDetail>();
        }
        return syscodeDetailMapper.selectList(new LambdaQueryWrapper<SyscodeDetail>().eq(SyscodeDetail::getSysCodeId, syscodes.get(0).getCodeId()));
    }
}
